import java.util.Scanner;

/**
 * @author caesar
 * @date 2025/6/30
 * @apiNote
 */
//4、声明变量balance并初始化为0，用以表示银行账户的余额，下面通过ATM机程序实现存款，取款等功能。
//
//---------ATM-------
//	1、存款
//	2、取款
//	3、显示余额
//	4、退出
//请选择：

//for循环解法
/*
public class practice4_4 {
    public static void main(String[] args) {
        double balance = 0;
        boolean flag = true;
        Scanner input = new Scanner(System.in);

        for (; flag == true; ) {
            System.out.println("---------ATM-------");
            System.out.println("1、存款");
            System.out.println("2、取款");
            System.out.println("3、显示余额");
            System.out.println("4、退出");
            System.out.print("请选择：");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入你想存储的金额：");
                    double money = input.nextDouble();
                    if(money < 0) {
                        System.out.println("取款失败");
                    }else if(money > 10000) {
                        balance += money;
                    System.out.println("存储成功");
                    }
                    break;
                case 2:
                    System.out.println("请输入你想取出的金额：");
                    money = input.nextDouble();
                    if(money < 0){
                        System.out.println("取款失败");
                    }else if (money > balance) {
                        System.out.println("余额不足");
                    } else {
                        balance -= money;
                        System.out.println("取款成功");
                    }
                    break;
                case 3:
                    System.out.println("您的余额为：" + balance);
                    break;
                case 4:
                    flag = false;
                    System.out.println("欢迎下次光临");
                    break;
            }
        }

        input.close();
    }
}
*/
//while循环解法
public class practice4_4 {
    public static void main(String[] args) {
        double balance = 0;
        boolean flag = true;
        Scanner input = new Scanner(System.in);
        while(flag) {
            System.out.println("---------ATM-------");
            System.out.println("1、存款");
            System.out.println("2、取款");
            System.out.println("3、显示余额");
            System.out.println("4、退出");
            System.out.print("请选择：");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入你想存储的金额：");
                    double money = input.nextDouble();
                    if(money < 0) {
                        System.out.println("取款失败");
                    }else if(money > 10000) {
                        balance += money;
                        System.out.println("存储成功");
                    }
                    break;
                case 2:
                    System.out.println("请输入你想取出的金额：");
                    money = input.nextDouble();
                    if(money < 0){
                        System.out.println("取款失败");
                    }else if (money > balance) {
                        System.out.println("余额不足");
                    } else {
                        balance -= money;
                        System.out.println("取款成功");
                    }
                    break;
                case 3:
                    System.out.println("您的余额为：" + balance);
                    break;
                case 4:
                    flag = false;
                    System.out.println("欢迎下次光临");
                    break;
            }
        }

        input.close();
    }
}
